package hot100.logos91To100;

/**
 * @author logos
 * date 2025/7/19 12:53
 * @version v1.0
 * @Package hot100.logos91To100
 */
public class logos97 {

    /**
     * 97. 多数元素
     * https://leetcode.cn/problems/majority-element/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public int majorityElement(int[] nums) {
            int ans = 0;
            int cnt = 0;
            for (int x : nums) {
                if (cnt == 0) {
                    ans = x;
                }
                cnt += x == ans ? 1 : -1;
            }
            return ans;
        }
    }
}
